<?php

class Todolist extends My_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('m_todolist');
    }
    function index()
    {
         if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        $data['nv'] = $this->m_account->lay_nhan_vien();
        $data['news'] = $this->m_todolist->lay_danh_sach_task_moi_chua_nhan();
        if($this->session->userdata('role') == 1)
        $data['news_old'] = $this->m_todolist->lay_danh_sach_task_moi_da_nhan(); 
        else if($this->session->userdata('role') == 3)  $data['news_old'] = $this->m_todolist->lay_danh_sach_task_moi_da_nhan_theo_account($this->session->userdata('accountid'));
        $this->load->view('todolist/index',$data);
        } else redirect('account/login_admin');
    }
    function add()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        if($this->input->post('luu') != '')
        {
            $url = $this->input->post('url1');
            $ACCOUNT_ID = null;
            if($this->input->post('account') != 0) $ACCOUNT_ID = $this->input->post('account');
            $TASK_TITLE = $this->input->post('tieude');
            $TASK_DETAILS = $this->input->post('chitiet');
            $START_DATE = $this->input->post('from');
            $DEADLINE = $this->input->post('to');
            $Level = $this->input->post('level');
            $STATUS = 1;
            $kq = $this->m_todolist->them_task($ACCOUNT_ID,$TASK_TITLE,$TASK_DETAILS,$START_DATE,$DEADLINE,$Level,$STATUS);
            redirect($url);
        }
          } else redirect('account/login_admin');
    }
        function edit()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        if($this->input->post('luu') != '')
        {
            $url = $this->input->post('url1');
            $id = $this->input->post('id_task');
            $ACCOUNT_ID = null;
            if($this->input->post('account') != 0) $ACCOUNT_ID = $this->input->post('account');
            $TASK_TITLE = $this->input->post('tieude');
            $TASK_DETAILS = $this->input->post('chitiet');
            $START_DATE = $this->input->post('from');
            $DEADLINE = $this->input->post('to');
            $Level = $this->input->post('level');
            $STATUS = 1;
            $kq = $this->m_todolist->cap_nhat_task($id,$ACCOUNT_ID,$TASK_TITLE,$TASK_DETAILS,$START_DATE,$DEADLINE,$Level,$STATUS);
            redirect($url);
        }
        } else redirect('account/login_admin');
    }
    function accept()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        if($this->input->post('luu') != '')
        {
            $url = $this->input->post('url1');
            $id = $this->input->post('id_task');
            $kq = $this->m_todolist->nhan_vien_accept($id,$this->session->userdata('accountid'));
            redirect($url);
        }
        } else redirect('account/login_admin');
    }
    function finish()
    {
         if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        if($this->input->post('luu') != '')
        {
            $url = $this->input->post('url1');
            $id = $this->input->post('id_task');
            $kq = $this->m_todolist->xong_task($id);
            redirect($url);
        }
        } else redirect('account/login_admin');
    }

}
?>